package com.baoxin.chenxixc4coach.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;


public class Course implements Parcelable {
    private String ofadId;
    private long ofadStartTime;
    private long ofadEndTime;
    private int ofadAlreadyNum;
    private int ofadMaxNum;
    private double ofadPrice;
    /**
     * 0未发布      1进行中 2 已满 3过期
     */
    private int ofadState;
    private Map<String, String> map;//科目+发布状态 "subject": 2, "ofaState": 1


    public Integer getSubject() {
        String a = map.get("subject");
        Integer b = Integer.parseInt(a);
        return b;
    }

    public String getOfadId() {
        return ofadId;
    }

    public int getOfadState() {
        return ofadState;
    }

    public String getPeriod() {
        Calendar calendarS = Calendar.getInstance();
        calendarS.setTimeInMillis(ofadStartTime);
        int hour = calendarS.get(Calendar.HOUR_OF_DAY);
        int min = calendarS.get(Calendar.MINUTE);
        StringBuilder sb = new StringBuilder();
        if (hour < 10) {
            sb.append("0").append(hour).append(":");
        } else {
            sb.append(hour).append(":");
        }
        if (min < 10) {
            sb.append("0").append(min);
        } else {
            sb.append(min);
        }

        Calendar calendarE = Calendar.getInstance();
        calendarE.setTimeInMillis(ofadEndTime);
        int hour1 = calendarE.get(Calendar.HOUR_OF_DAY);
        int min1 = calendarE.get(Calendar.MINUTE);
        StringBuilder sb1 = new StringBuilder();
        if (hour1 < 10) {
            sb1.append("0").append(hour1).append(":");
        } else {
            sb1.append(hour1).append(":");
        }
        if (min1 < 10) {
            sb1.append("0").append(min1);
        } else {
            sb1.append(min1);
        }
        return sb.toString() + "-" + sb1.toString();
    }

    public int getOfadAlreadyNum() {
        return ofadAlreadyNum;
    }

    public int getOfadMaxNum() {
        return ofadMaxNum;
    }


    public double getOfadPrice() {
        return ofadPrice;
    }

    public Course() {
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.ofadId);
        dest.writeLong(this.ofadStartTime);
        dest.writeLong(this.ofadEndTime);
        dest.writeInt(this.ofadAlreadyNum);
        dest.writeInt(this.ofadMaxNum);
        dest.writeDouble(this.ofadPrice);
        dest.writeInt(this.ofadState);
        dest.writeInt(this.map.size());
        for (Map.Entry<String, String> entry : this.map.entrySet()) {
            dest.writeString(entry.getKey());
            dest.writeString(entry.getValue());
        }
    }

    protected Course(Parcel in) {
        this.ofadId = in.readString();
        this.ofadStartTime = in.readLong();
        this.ofadEndTime = in.readLong();
        this.ofadAlreadyNum = in.readInt();
        this.ofadMaxNum = in.readInt();
        this.ofadPrice = in.readDouble();
        this.ofadState = in.readInt();
        int mapSize = in.readInt();
        this.map = new HashMap<String, String>(mapSize);
        for (int i = 0; i < mapSize; i++) {
            String key = in.readString();
            String value = in.readString();
            this.map.put(key, value);
        }
    }

    public static final Creator<Course> CREATOR = new Creator<Course>() {
        @Override
        public Course createFromParcel(Parcel source) {
            return new Course(source);
        }

        @Override
        public Course[] newArray(int size) {
            return new Course[size];
        }
    };
}
